package com.cyjf.biz.impl;

import com.cyjf.biz.service.CarDealerService;
import com.cyjf.dbview.bo.*;
import com.cyjf.dbview.mapper.ZscarDealerMapper;
import com.cyjf.dbview.mapper.ZscarBazaarMapper;
import com.cyjf.dbview.mapper.ZscarProvincesMapper;

import com.cyjf.util.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*
*【整车交易】
 */
@Service("carDealerService")
@Slf4j
public class CarDealerServiceImpl implements CarDealerService {

    @Resource
    private ZscarDealerMapper zscarDealerMapper;

    @Resource
    private ZscarBazaarMapper  zscarBazaarMapper;

    @Resource
    private ZscarProvincesMapper zscarProvincesMapper;


    //车商、业务员相关统计
    @Override
    public ResultVO newAddCarDealer() {
        ResultVO<CarDealerCountBO> resultVO = new ResultVO();
        CarDealerCountBO  carDealerCountBO = new CarDealerCountBO();

        //CarDealerCountBO  carDealerCountBO = ZscarDealerMapper.getTotalAddAmount();

        //今日新增车商数
        Integer  todayaddAmount = zscarDealerMapper.getToadyAddAmount();
        carDealerCountBO.setTodayaddAmount(todayaddAmount);

        //累计车商数
        Integer totalAmount = zscarDealerMapper.getTotalAmount();
        carDealerCountBO.setTotalAmount(totalAmount);

        //已拓展二手车市场
        Integer usedCarMarket = zscarBazaarMapper.getUsedCarMarket();
        carDealerCountBO.setUsedCarMarket(usedCarMarket);

        //业务员车商数量
        List<StaffBO> staffDealer =  zscarDealerMapper.getStaffDealer();
        carDealerCountBO.setStaffDealer(staffDealer);

        //车商地域分布-按照省份
        List<StaffBO> dealerAreaAmount = zscarDealerMapper.getDealerAreaAmount();
        carDealerCountBO.setDealerAreaAmount(dealerAreaAmount);

        //近7天订单统计
        List<OrderBO> orderCount = zscarDealerMapper.orderCount();
        carDealerCountBO.setOrderCount(orderCount);


//        if (carDealerCountBO == null) {
//            log.error(ErrorContent.QIANHAI_INTEFACE_NO_DATA_MESSAGE);
//            resultVO.setMessage(ErrorContent.QIANHAI_INTEFACE_NO_DATA_MESSAGE);
//        }else
//            resultVO.setMessage("成功");

        resultVO.setData(carDealerCountBO);

        return resultVO;
    }

    //省份统计
    @Override
    public ResultVO provincesAmount() {
        ResultVO<ProvinceBO> resultVO = new ResultVO();
        ProvinceBO provinceBO = new ProvinceBO();
        //市场详情-按省份统计
        List<ProvinceBO>  provincesAmount =    zscarProvincesMapper.getProvincesCount();
        provinceBO.setProvincesCount(provincesAmount);

        resultVO.setData(provinceBO);
        return resultVO;
    }

    //渠道占比
    @Override
    public ResultVO channelProportion() {
        ResultVO<ChannelBO> resultVO = new ResultVO();
        ChannelBO channelBO = new ChannelBO();

        List<ChannelBO>  channelList =    zscarDealerMapper.channelProportion();
        channelBO.setChannelProportion(channelList);

        resultVO.setData(channelBO);
        return resultVO;
    }


    //【整车交易】市场详情-列表
    @Override
    public ResultVO MarketDetail(String prov) {
        ResultVO<MarketBO> resultVO = new ResultVO();
        MarketBO marketBO = new MarketBO();

        List<MarketBO>  marketDetailList = zscarProvincesMapper.getMarketDetail(prov);
        MarketDetailCountBO marketDetailCountBO = zscarProvincesMapper.getMarketDetailCount();
        marketBO.setMarketDetailList(marketDetailList);
        marketBO.setMarketDetailCountBO(marketDetailCountBO);

        resultVO.setData(marketBO);
        return resultVO;
    }

}
